<template>
  <div class="zs-table-page-container">
    <SearchTabTime :tabList="tabList" :curTabIndex="curTabIndex" @onChange="changeTab" :tag="``"></SearchTabTime>
    <div class="zs-card zs-table-page-content" v-loading="loading">
      <ProjectTable :cardPermis="tabList[curTabIndex].cardPermis" :title="tabList[curTabIndex].title" :tableData="tableData" :updateDate="updateDate" :tabPermi="tabList[curTabIndex].permi"></ProjectTable>
    </div>
  </div>
</template>
<script setup>
import SearchTabTime from '@/DbComponents/searchTabTime'
import ProjectTable from './projectTable.vue'
import dbPublicApi from '@/api/dbPublic'
import { ref } from 'vue'

const tabList = ref([
  { label: '自营创新', value: '自营创新', permi: 'p_btn_901_guantingxiangmu_zycx', title: '自营创新项目详情', cardPermis: ['p_btn_901_gt_zycx_xiangqing_startupexpenses', 'p_btn_901_gt_zycx_xiangqing_commercialprofit', 'p_btn_901_gt_zycx_xiangqing_lnputoutput', 'p_btn_901_gt_zycx_xiangqing_sourceandfunds'] },
  { label: '轻资产', value: '轻资产', permi: 'p_btn_901_guantingxiangmu_qzc', title: '轻资产项目详情', cardPermis: ['p_btn_901_gt_qzc_xiangqing_startupexpenses', 'p_btn_901_gt_qzc_xiangqing_commercialprofit', 'p_btn_901_gt_qzc_xiangqing_lnputoutput', 'p_btn_901_gt_qzc_xiangqing_sourceandfunds'] },
  { label: '轻拓平台', value: '轻拓平台', permi: 'p_btn_901_guantingxiangmu_qtpt', title: '轻拓平台项目详情', cardPermis: ['p_btn_901_gt_qtpt_xiangqing_startupexpenses', 'p_btn_901_gt_qtpt_xiangqing_commercialprofit', 'p_btn_901_gt_qtpt_xiangqing_lnputoutput', 'p_btn_901_gt_qtpt_xiangqing_sourceandfunds'] },
  { label: '管理公司', value: '管理公司', permi: 'p_btn_901_guantingxiangmu_glgs', title: '管理公司项目详情', cardPermis: ['p_btn_901_gt_glgs_xiangqing_startupexpenses', 'p_btn_901_gt_glgs_xiangqing_commercialprofit', 'p_btn_901_gt_glgs_xiangqing_lnputoutput', 'p_btn_901_gt_glgs_xiangqing_sourceandfunds'] },
  { label: '科技', value: '科技', permi: 'p_btn_901_guantingxiangmu_kj', title: '科技项目详情', cardPermis: ['p_btn_901_gt_kj_xiangqing_startupexpenses', 'p_btn_901_gt_kj_xiangqing_commercialprofit', 'p_btn_901_gt_kj_xiangqing_lnputoutput', 'p_btn_901_gt_kj_xiangqing_sourceandfunds'] },
  { label: '不动产', value: '不动产', permi: 'p_btn_901_guantingxiangmu_bdc', title: '不动产项目详情', cardPermis: ['p_btn_901_gt_bdc_xiangqing_startupexpenses', 'p_btn_901_gt_bdc_xiangqing_commercialprofit', 'p_btn_901_gt_bdc_xiangqing_lnputoutput', 'p_btn_901_gt_bdc_xiangqing_sourceandfunds'] },
  { label: '北京汇聚', value: '北京汇聚', permi: 'p_btn_901_guantingxiangmu_bjhz', title: '北京汇聚项目详情', cardPermis: ['p_btn_901_gt_bjhz_xiangqing_startupexpenses', 'p_btn_901_gt_bjhz_xiangqing_commercialprofit', 'p_btn_901_gt_bjhz_xiangqing_lnputoutput', 'p_btn_901_gt_bjhz_xiangqing_sourceandfunds'] },
  { label: '其他', value: '其他', permi: 'p_btn_901_guantingxiangmu_guanting', title: '其他项目详情', cardPermis: ['p_btn_901_guantingxiangmu_xiangqing_kaibanfei', 'p_btn_901_guantingxiangmu_xiangqing_lirunbiao', 'p_btn_901_guantingxiangmu_xiangqing_trycc', 'p_btn_901_guantingxiangmu_xiangqing_zjzyyly'] },
])
const curTabIndex = ref(0)

let tag = ref('')
const loading = ref(true)
const tableData = ref([])
const updateDate = ref('')
const getDate = async (menuKey) => {
  await dbPublicApi.queryDataTimeApi(menuKey).then((res) => {
    if (res.data.code == 200) {
      tag.value = res.data.message
      updateDate.value = res.data.data
    }
  })
}
const getList = async () => {
  await dbPublicApi.queryProjectPcApi({ dataTime: updateDate.value, resourceKey: tabList.value[curTabIndex.value].permi }).then((res) => {
    if (res.data.code == 200) {
      tableData.value = res.data.data
    }
  })
}
const getTabIndex = async () => {
  let list = await JSON.parse(localStorage.getItem('portalResourceList'))
  if (!list) { return false }
  for (let [index, tab] of tabList.value.entries()) {
    if (list.indexOf(tab.permi) > -1) {
      curTabIndex.value = index
      break;
    }
  }
}
const changeTab = async (data) => {
  loading.value = true
  curTabIndex.value = data.data
  tableData.value = []
  await getDate(tabList.value[curTabIndex.value].permi)
  await getList()
  loading.value = false
}
const init = async () => {
  await getTabIndex()
  if (curTabIndex.value == -1) {
    loading.value = false
    return false
  }
  await getDate(tabList.value[curTabIndex.value].permi)
  await getList()
  loading.value = false
}
init()

</script>


<style scoped lang="scss"></style>
